﻿using System;
using System.Collections.Generic;
using System.Device.Location;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace RadarControl.Helpers
{
    public static class LocationHelper
    {
        public static double CacheAzimuth(GeoCoordinate currentCoordinate, GeoCoordinate destinationCoorinate)
        {
            double y = Math.Sin((destinationCoorinate.Longitude - currentCoordinate.Longitude) * Math.PI / 180) * Math.Cos(destinationCoorinate.Latitude * Math.PI / 180);
            double x = Math.Cos(currentCoordinate.Latitude * Math.PI / 180) * Math.Sin(destinationCoorinate.Latitude * Math.PI / 180) -
                Math.Sin(currentCoordinate.Latitude * Math.PI / 180) * Math.Cos(destinationCoorinate.Latitude * Math.PI / 180) * Math.Cos((destinationCoorinate.Longitude - currentCoordinate.Longitude) * Math.PI / 180);
            double cacheAzimuth = (Math.Atan2(y, x) * 180 / Math.PI + 360) % 360;

            return cacheAzimuth;
        }

        public static double CalculateDistance(GeoCoordinate currentCoordinate, GeoCoordinate destinationCoorinate)
        {
            return currentCoordinate.GetDistanceTo(destinationCoorinate);
        }
    }
}
